<!DOCTYPE html>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2023/6/13
  Time: 10:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%--
  Created by IntelliJ IDEA.
  User: M
  Date: 2023/6/23
  Time: 11:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.8.6/dist/css/layui.css" rel="stylesheet">
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">

    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
    <style>
        .layui-table-box{
            /*width: 900px;*/
            /*padding-right: 200px;*/
        }
    </style>
</head>
<body>
<div id="addForm" style="display: none;">
    <form class="layui-form layui-form-pane" id="fm" lay-filter="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-block">
                <select name="orderId" lay-verify="">
                    <option value="" id="orderId"></option>
                </select>
            </div>
            <label class="layui-form-label">请选择部门</label>
            <div class="layui-input-block">
                <select name="departmentId" lay-verify="-1" id="departmentId">
                    <option value="-1">请选择部门</option>
                    <option value="1">裁剪部</option>
                    <option value="2">缝纫部</option>
                    <option value="3">质检部</option>
                    <option value="4">厂部</option>
                    <option value="5">技术科</option>
                </select>
            </div>
            <label class="layui-form-label">商品</label>
            <div class="layui-input-block">
                <select name="productDetailId" lay-verify="">
                    <option value="" id="id"></option>
                </select>
            </div>
            <label class="layui-form-label">尺寸</label>
            <div class="layui-input-block">
                <select name="sizeId" lay-verify="-1" id="sizeId">
                    <option value="-1">请选择衣服的尺寸</option>
                    <option value="1">S</option>
                    <option value="2">M</option>
                    <option value="3">L</option>
                    <option value="4">XL</option>
                    <option value="5">XXL</option>
                    <option value="6">3XL</option>
                    <option value="7">4XL</option>
                </select>
            </div>
            <label class="layui-form-label">今日已生产数量</label>
            <div class="layui-input-block">
                <input type="text" name="schedeleCount" lay-verify="required" placeholder="今日已生产数量" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">库存</label>
            <div class="layui-input-block">
                <select name="productionCount" lay-verify="">
                    <option value="" id="productionCount"></option>
                </select>
            </div>
        </div>
    </form>
</div>

<div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1" lay-id="demo" style=" height:312px;">
    <div class="layui-table-tool">
        <div class="layui-table-tool-temp">
            <div class="layui-btn-container">
                <%--                <button class="layui-btn layui-btn-sm" lay-event="customers" onclick=toAddClass()>--%>
                <%--                    添加</button>--%>
            </div>
        </div>
        <div class="layui-table-tool-self">
            <div class="layui-inline" title="筛选列" lay-event="LAYTABLE_COLS">
                <i class="layui-icon layui-icon-cols"></i>
            </div><div class="layui-inline" title="导出" lay-event="LAYTABLE_EXPORT">
            <i class="layui-icon layui-icon-export"></i></div><div class="layui-inline" title="打印" lay-event="LAYTABLE_PRINT">
            <i class="layui-icon layui-icon-print"></i></div></div></div><div class="layui-table-box"><div class="layui-table-header">
    <table cellspacing="0" cellpadding="0" border="0" class="layui-table"><thead><tr><th data-field="clientId" data-key="1-0-0" class=" layui-unselect">
    </table>
    <table id="demo" lay-filter="test"></table>
</div>
</div>
</div>

<script src="/layui/layui.js"></script>
<script>
    layui.use('table', function() {
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo'
            , height: 312
            , url: 'Product/getQualityAll' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'quotationNumber', title: '订单编号', width: 80},
                {field: 'productName', title: '商品名称', width: 80},
                {field: 'schedeleCount', title: '计划生产数量', width: 120},
                {field: 'staffDepartment', title: '部门', width: 100},
                {field: 'name', title: '尺码', width: 150},
                {field: '', title: '操作', width: 150, toolbar: "#toolbarDemo"},
            ]]
        });
    })
</script>
<script type="text/javascript">
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add" onclick="toAddClass()">添加</button>
    </div>
</script>
<script type="text/javascript">
    getProdutOcsrId();
    queryProductDetail();
    queryStore();
    //订单编号
    function getProdutOcsrId() {
        $.ajax({
            "url": "Product/queryOrderForm",
            "type": "get",
            "data": {},
            "dataType": "json",
            // contentType:"application/json;charset=utf-8",
            "success": function (result) {
                let optemp = "";
                for (let i in result) {
                    optemp += `<option value="\${result[i].orderId}">\${result[i].quotationNumber}</option>
                `
                }
                $('#orderId').after(optemp)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error": function () {
                // alert("出错了")
            }
        });
    }
    function queryProductDetail() {
        //商品
        $.ajax( {
            "url"            :  "Product/queryProductDetail",
            "type"         :  "get",
            "data"         : {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let optemp1="";
                for (let i in result){
                    optemp1+=`
               <option value="\${result[i].id}">\${result[i].productName}</option>
                `
                }
                $("#id").empty();
                $("#id").after(optemp1);

            },
            "error"       :  function() {
                // alert("出错了")
            }
        } );
    }
    function queryStore() {

        $.ajax( {
            "url"            :  "Product/queryStore",
            "type"         :  "get",
            "data"         : {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let optemp2="";
                for (let i in result){
                    optemp2+=`
               <option value="\${result[i].productionCount}">\${result[i].productionCount}</option>
                `
                }
                $("#productionCount").empty();

                $("#productionCount").after(optemp2);

            },
            "error"       :  function() {
                // alert("出错了")
            }
        } );
    }
    function toAddClass(){
        var form = layui.form;
        form.render(null,'addForm');
        layer.open({
            type: 1,
            title: '添加',
            content: $("#addForm"),
            area: ['800px', '500px'], // 弹窗大小
            btn: ['确定', '取消'],
            yes: function(index, layero) {
                let data = {}
                let value = $("#fm").serializeArray()
                $.each(value, function(index, item) {
                    data[item.name] = item.value;
                });
                let Qua = JSON.stringify(data);
                // isNullAllEmtype();
                $.ajax({
                    "url": "Product/addProQuaAll",
                    "type": "post",
                    "data": Qua,
                    "dataType": "json",
                    "contentType": "application/json;charset=utf-8",
                    "success": function(result) {
                    },
                    "error": function() {
                    }
                });
                $.ajax({
                    "url": "Product/addProQductPlan",
                    "type": "post",
                    "data": Qua,
                    "dataType": "json",
                    "contentType": "application/json;charset=utf-8",
                    "success": function(result) {
                        if(result>0){
                            layui.msg("添加成功");
                        }
                    },
                    "error": function() {
                    }
                });
                layer.close(index); // 关闭弹窗
                var table = layui.table;
                table.reload('demo');
                console.log($("#fm"))
                $("#fm")[0].reset();
            }
        });
    }
    // function isNullAllEmtype() {
    //     let orderId= $('[name=orderId]').val();
    //     let productDetailId=$('[name=productDetailId]').val();
    //     let departmentId=$('[name=departmentId]').val();
    //     let sizeId=$('[name=sizeId]').val();
    //     let schedeleCount=$('[name=schedeleCount]').val();
    //     let productionCount=$('[name=productionCount]').val();
    //
    //     if(orderId!=null||orderId!=""){
    //         alert("订单编号不能为空")
    //         return false;
    //     }
    //     if(productionCount!=null||productionCount!=""){
    //         alert("库存不能为空")
    //         return false;
    //     }
    //     if(schedeleCount!=null||schedeleCount!=""){
    //         alert("今日生产数量不能为空")
    //         return false;
    //     }
    //     if(sizeId!=null||sizeId!=""){
    //         alert("尺寸不能为空")
    //         return false;
    //     }
    //     if(productDetailId!=null||productDetailId!=""){
    //         alert("商品不能为空")
    //         return false;
    //     }
    //     if(departmentId!=null||departmentId!=""){
    //         alert("部门编号不能为空")
    //         return false;
    //     }
    // }
</script>
</body>
</html>